package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.BaseCapacityRule;
import com.sailfish.springbootdemo.service.db1.BaseCapacityRuleService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/baseCapacityRule")
public class BaseCapacityRuleController {

    @Autowired
    private BaseCapacityRuleService baseCapacityRuleService;

    @PostMapping("/getAllBaseCapacityRule")
    public Result getAllBaseCapacityRule(String searchValue, Integer lineBaseBigTypeId, Integer lineBaseSmallTypeId) {
        try {
            return ResultUtil.success(baseCapacityRuleService.getAllBaseCapacityRule(searchValue, lineBaseBigTypeId, lineBaseSmallTypeId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/updateBaseCapacityRule")
    public Result updateBaseCapacityRule(BaseCapacityRule baseCapacityRule) {
        return baseCapacityRuleService.updateBaseCapacityRule(baseCapacityRule);
    }

    @PostMapping("/deleteBaseCapacityRule")
    public Result deleteBaseCapacityRule(Integer baseCapacityRuleId) {
        return baseCapacityRuleService.deleteBaseCapacityRule(baseCapacityRuleId);
    }

    @PostMapping("/addOrUpdateBaseCapacityRule")
    public Result addOrUpdateBaseCapacityRule(String mode, BaseCapacityRule baseCapacityRule) {
        return baseCapacityRuleService.addOrUpdateBaseCapacityRule(mode, baseCapacityRule);
    }
}
